You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.0 KiB
31 lines
1.0 KiB
import { defineWrappedResponseHandler } from "#server/utils/handler";
|
|
import { R } from "#server/utils/response";
|
|
import { resolveAgentIdentity } from "#server/service/agent/identity";
|
|
import { getSessionByIdAndUser, updateSession } from "#server/service/agent/session";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const identity = await resolveAgentIdentity(event);
|
|
const id = getRouterParam(event, "id");
|
|
if (!id) {
|
|
return R.error("参数无效", null);
|
|
}
|
|
|
|
const session = await getSessionByIdAndUser(id, identity.userId, identity.tempToken);
|
|
if (!session) {
|
|
return R.error("会话不存在", null);
|
|
}
|
|
|
|
const body = await readBody(event);
|
|
const { title } = body as { title?: string };
|
|
|
|
if (!title || typeof title !== "string" || title.trim().length === 0) {
|
|
return R.error("标题不能为空", null);
|
|
}
|
|
|
|
if (title.length > 100) {
|
|
return R.error("标题不能超过100字符", null);
|
|
}
|
|
|
|
await updateSession(id, { title: title.trim() });
|
|
return R.success({ id, title: title.trim() });
|
|
});
|
|
|